package com.example.permanentroom;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.google.gson.Gson;

import java.util.ArrayList;

import Entity.commodity;
import Service.LiebiaoService;

public class liebiao extends AppCompatActivity {
   public static String type="";
   private commodity com1;
    private commodity com2;
    private commodity com3;
    private commodity com4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.liebiao);
        Gson gson=new Gson();
        Context ctx=getBaseContext();
        ArrayList<commodity> arr=new ArrayList<>();
        if(type.equals("QX")){
            arr=new LiebiaoService().get_type("球鞋");
        }
        if(type.equals("HZP")){
            arr=new LiebiaoService().get_type("化妆品");
        }
        if(type.equals("SB")){
            arr=new LiebiaoService().get_type("手表");
        }
        String Json1 = gson.toJson(arr.get(0));
        String Json2 = gson.toJson(arr.get(1));
        String Json3 = gson.toJson(arr.get(2));
        String Json4 = gson.toJson(arr.get(3));

        com1 = gson.fromJson(Json1, commodity.class);
        com2 = gson.fromJson(Json2, commodity.class);
        com3 = gson.fromJson(Json3, commodity.class);
        com4 = gson.fromJson(Json4, commodity.class);

        ImageView img1=findViewById(R.id.item1img);
        ImageView img2=findViewById(R.id.item2img);
        ImageView img3=findViewById(R.id.item3img);
        ImageView img4=findViewById(R.id.item4img);

        int resId1 = getResources().getIdentifier("item"+com1.getId(), "drawable" , ctx.getPackageName());
        int resId2 = getResources().getIdentifier("item"+com2.getId(), "drawable" , ctx.getPackageName());
        int resId3 = getResources().getIdentifier("item"+com3.getId(), "drawable" , ctx.getPackageName());
        int resId4 = getResources().getIdentifier("item"+com4.getId(), "drawable" , ctx.getPackageName());

        img1.setImageResource(resId1);
        img2.setImageResource(resId2);
        img3.setImageResource(resId3);
        img4.setImageResource(resId4);

        TextView tv1=findViewById(R.id.item1);
        TextView tv2=findViewById(R.id.item2);
        TextView tv3=findViewById(R.id.item3);
        TextView tv4=findViewById(R.id.item4);

        tv1.setText(com1.getCommoname()+"\n ￥"+com1.getPrice());
        tv2.setText(com2.getCommoname()+"\n ￥"+com2.getPrice());
        tv3.setText(com3.getCommoname()+"\n ￥"+com3.getPrice());
        tv4.setText(com4.getCommoname()+"\n ￥"+com4.getPrice());
    }



    public void goShouye(View view) {
        Intent intent=new Intent(this,shouye.class);
        startActivity(intent);
        this.finish();
    }
    public void goGouwuche(View view) {
        Intent intent=new Intent(this,gouwuche.class);
        startActivity(intent);
        this.finish();
    }
    public void goWode(View view) {
        Intent intent=new Intent(this,wode.class);
        startActivity(intent);
        this.finish();
    }
    public void add1(View view) {
        addto_gouwuche(1);
    }
    public void add2(View view) {
        addto_gouwuche(2);
    }
    public void add3(View view) {
        addto_gouwuche(3);
    }
    public void add4(View view) {
        addto_gouwuche(4);
    }
    public void addto_gouwuche(int number) {
        commodity com=new commodity();
        if(number==1){com=com1;}
        if(number==2){com=com2;}
        if(number==3){com=com3;}
        if(number==4){com=com4;}
        gouwuche.order= gouwuche.order+com.getCommoname()+"\n\n";
        gouwuche.price= gouwuche.price+"￥  "+com.getPrice()+"\n\n";
        Integer in=com.getId();
        gouwuche.comidlist.add(in);
    }


}